#include "MainFramework.h"

// setup rasterization platform
void RenderInit()
{
  glFrontFace(GL_CW);
  glEnable(GL_AUTO_NORMAL);
  glEnable(GL_NORMALIZE);
  glEnable(GL_DEPTH_TEST);
}

// setup viewport
void RenderViewport(ui32 width, ui32 height)
{
  // limit size to min 1 pixel width/height
  if (width == 0) width = 1;
  if (height == 0) height = 1;

#ifdef OPENGL
  // setup viewport parameters
  glViewport(0, 0, (GLsizei)width, (GLsizei)height);

  // switch to projection matrix mode and load Identity
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();

  // TODO: camera has to be used here!!!

  // create a perspective view
  gluPerspective(25.0f, 16.0f/9.0f, 0.1f, 1000.0f);

  // switch to view matrix mode and load Identity
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
#endif
};

// clear screen
void RenderClear()
{
#ifdef OPENGL
   // clear all buffers in the rasterization pipeline
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
#endif
};

// mark screen as "needs to be redrawn"
void RenderInvalidate()
{
#ifdef GLUT
  glutPostRedisplay(); // invalidate current screen
#endif // GLUT
};

// swap back-/frontbuffer
void RenderSwapBuffers()
{
#ifdef OPENGL
  glFlush(); // flush OpenGL pipeline processing
#endif // OPENGL

#ifdef GLUT
  glutSwapBuffers(); // tell window manager to swap buffers
#endif // GLUT
};
